<?php
   require_once "Model.php";
   require_once "../common/connDB.php";
   class IndexModel extends Model{
     
   	 public function __construct(){
        parent::__construct();
   	 }
   	 //获取用户列表
   	 public function getUserList(){
      $sql="select * from student";
      $data=$this->conn->query($sql);
     	return $data;
     }
     //获取卷纸列表
      public function getPaperList(){
      $sql="select * from papers";
      $data=$this->conn->query($sql);
     	return $data;
     }
     //获取试题列表
     public function getTestList(){
      $sql="select * from test";
      $data=$this->conn->query($sql);
     	return $data;
     }
     //删除用户信息方法
     public function deleteUserInfo()
		{
			$sid = $_GET['sid'];

			$sql = "delete from student where sid={$sid}";
			$result = $this -> conn -> query($sql);
			return $result;
		}
	//删除卷纸
	public function deletePaperInfo()
		{
			$pid = $_GET['pid'];

			$sql = "delete from papers where pid={$pid}";
			$result = $this -> conn -> query($sql);
			return $result;
		}
		//删除试题
		public function deleteTestInfo()
		{
			$tid = $_GET['tid'];

			$sql = "delete from test where tid={$tid}";
			$result = $this -> conn -> query($sql);
			return $result;
		}
		//通过pid获取卷纸数据
		public function getPaperByID()
		{
			$pid = $_GET['pid'];
			$sql = "select * from papers where pid=$pid";
			//echo $sql;
			$data = $this-> conn -> query($sql);
			return $data;
		}
		//搜索卷纸
		public function getPaperByName()
		{
			$pname = $_POST['pname'];
			$sql = "select * from papers where pname='$pname'";
			//echo $sql;
			$data = $this-> conn -> query($sql);
			return $data;
		}
		//通过pname->pid->data
		public function getTestByName()
		{
			$pname = $_POST['pname'];
			$sql = "select * from papers where pname='$pname'";
			//echo $sql;
			$data = $this-> conn -> query($sql);
			$pid = $data['pid'];
			$sql = "select * from test where pid=$pid";
			$data = $this-> conn -> query($sql);
			return $data;
		}
		//通过tid获取试题数据
		public function getTestByID()
		{
			$tid = $_GET['tid'];
			$sql = "select * from test where tid=$tid";
			//echo $sql;
			$data = $this-> conn -> query($sql);
			return $data;
		}
		//通过sid获取学生数据
		public function getUserByID()
		{
			$sid = $_GET['sid'];
			$sql = "select * from student where sid=$sid";
			//echo $sql;
			$data = $this-> conn -> query($sql);
			return $data;
		}
		//更新卷纸数据
		public function updatePaperInfo()
		{
			//使用$_POST数组获取表单中输入的数据
		  $pid = $_POST['pid'];
		  $pname = trim($_POST['pname']);  
		  $createtime = $_POST['createtime'];
		  $totaltime = $_POST['totaltime'];
		 

	
		$sql = "update papers set pname='{$pname}', createtime='{$createtime}', totaltime={$totaltime} where pid={$pid}";	
		//echo $sql;		
		
		  	//echo $sql;
		  	$result = $this -> conn -> query($sql);//写入数据库
			return $result;
		
		}
		//更新用户信息
		public function updateUserInfo()
		{
			//使用$_POST数组获取表单中输入的数据
		  $sid = $_POST['sid'];
		  $sname = trim($_POST['sname']);  
		  $password = $_POST['password'];
		
		 

	
		$sql = "update student set sid='{$sid}', sname='{$sname}', password=md5('$password') where sid={$sid}";	
		//echo $sql;		
		
		  	//echo $sql;
		  	$result = $this -> conn -> query($sql);//写入数据库
			return $result;
		
		}
		//更新试题数据
		public function updateTestInfo()
		{
			//使用$_POST数组获取表单中输入的数据
		  $tid = $_POST['tid'];
			 
		$content = $_POST['content'];
		$score = $_POST['score'];
		$op1 = $_POST['op1'];
		$pic1 = $pic1 = $this->uploadfile("pic1",'../images/');
		$op2 = $_POST['op2'];
		$pic2 = $pic1 = $this->uploadfile("pic2",'../images/');
		$op3 = $_POST['op3'];
		$pic3 = $pic1 = $this->uploadfile("pic3",'../images/');
		$op4 = $_POST['op4'];
		$pic4 = $pic1 = $this->uploadfile("pic4",'../images/');
		$ans = $_POST['ans'];
		$pid = $_POST['pid'];
		//echo $pid;
		//$sql = "select * from  papers where pid={$pid}";	
		//echo $sql;		
		
		  	//echo $sql;
		 //$result = $this -> conn -> query($sql);//写入数据库
		
		 	$sql = "update test set content ='{$content}', score={$score},op1 = '{$op1}',pic1 = '{$pic1}',op2 = '{$op2}',pic2 = '{$pic2}',op3 = '{$op3}',pic3 = '{$pic3}',op4 = '{$op4}',pic4 = '{$pic4}',ans = '{$ans}',	pid={$pid} where tid={$tid}";
		 	//echo $sql;
		 	$result = $this -> conn -> query($sql);
		 	return $result;

		
		}
		//添加卷纸数据
		public function addPaperInfo()
	    {
	      //使用$_POST数组获取表单中输入的数据
	        $pid = $_POST['pid']; 
	        $pname = $_POST['pname'];
	        $createtime = $_POST['createtime'];
	         $totaltime = $_POST['totaltime'];
	        $sql = "insert into papers values('$pid','$pname','$createtime','$totaltime')";
	        
	        $result = $this -> conn -> query($sql);//写入数据库
	        return $result;
	    }
	    //添加试题
	    public function addTestInfo()
	    {
	      //使用$_POST数组获取表单中输入的数据
	        $content = $_POST['content'];
			$score = $_POST['score'];
			$op1 = $_POST['op1'];
			$pic1 = $pic1 = $this->uploadfile("pic1",'../images/');
			$op2 = $_POST['op2'];
			$pic2 = $pic1 = $this->uploadfile("pic2",'../images/');
			$op3 = $_POST['op3'];
			$pic3 = $pic1 = $this->uploadfile("pic3",'../images/');
			$op4 = $_POST['op4'];
			$pic4 = $pic1 = $this->uploadfile("pic4",'../images/');
			$ans = $_POST['ans'];
			$pid = $_POST['pid'];
	        $sql = "insert into test values(null,'单选题','$content', '$score','$op1','$pic1','$op2','$pic2','$op3','$pic3','$op4','$pic4','$ans','$pid')";
	        
	        $result = $this -> conn -> query($sql);//写入数据库
	        return $result;
	    }
   }

?>